import { createStore } from 'vuex'

export default createStore({
  state: {
    cartList:[], // 购物车的数据
  },
  mutations: {
    addCart(state,val){
      let index = state.cartList.findIndex(item => item.id == val.id);
      if (index>-1){ // 判断购物车的数据是否已经存在
        state.cartList[index].num++;
      } else {
        state.cartList.push(val);
      }
      
    },
    del(state){
      state.cartList = state.cartList.filter(item => !item.ischeck);
    }
  },
  actions: {
  },
  modules: {
  }
})
